package com.qidian.mespro.controller;

import com.github.pagehelper.PageInfo;
import com.qidian.mespro.service.ProductOrderService;
import com.qidianit.mes.pojo.ProductOrder;
import com.qidianit.mes.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ author: 周晓轩
 * @ company 起点编程
 * @ time: 2025/9/20 - 15:05
 * @ Description:
 */
@RestController
@RequestMapping("/productionOrder")
public class ProductOrderController {

    @Autowired
    private ProductOrderService productOrderService;

    @GetMapping("/list")
    public Result<PageInfo<ProductOrder>> getList(ProductOrder order, String materialName, Integer status, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize) {
        return productOrderService.productOrderList(order, materialName, status,pageNum, pageSize);
    }

    @GetMapping("/{id}")
    public Result<ProductOrder> getById(@PathVariable("id") Long id) {
        return productOrderService.getProductionOrderById(id);
    }

    @PostMapping("/add")
    public Result<ProductOrder> add(@RequestBody ProductOrder productOrder) {
        return productOrderService.addProductionOrder(productOrder);
    }

    @PutMapping("/update")
    public Result update(@RequestBody ProductOrder productOrder) {
        return productOrderService.updateProductOrder(productOrder);
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Long id){
        return productOrderService.deleteProductOrderById(id);
    }

    @PostMapping("/confirm/{id}")
    public Result<?> confirm(@PathVariable("id") Long id, @RequestParam Long updatorId) {
        return productOrderService.confirmProductionOrder(id, updatorId);
    }

    @PostMapping("/audit/{id}")
    public Result<?> audit(@PathVariable("id") Long id, @RequestParam Integer auditResult, @RequestParam String auditOpinion, @RequestParam Long updatorId) {
        return productOrderService.auditProductionOrder(id, auditResult, auditOpinion, updatorId);
    }

    @GetMapping("/autoCode")
    public Result<String> getAutoCode() {
        return productOrderService.getAutoCode();
    }
}
